def check_usage
  unless ARGV.length == 2
    puts "Usage: differences.rb old-inventory new-inventory"
    exit
  end
end

def boring?(line, boring_words)
  boring_words.any? do | a_boring_word |
    contains?(line, a_boring_word)
  end
end

def contains?(line, a_boring_word)
  line.chomp.split("/").include?(a_boring_word)
end

def inventory_from(file_name)
  downcased = File.open(file_name).collect do | line |
    line.downcase
  end

  downcased.reject do | line |
    boring?(line, ["temp", "recycler"])
  end
end

def compare_inventory_files(old_file, new_file)
  old_inventory = inventory_from(old_file)
  new_inventory = inventory_from(new_file)
  print_add_files(old_inventory, new_inventory)
  print_delete_files(old_inventory, new_inventory)
end


def print_add_files(old_inventory, new_inventory)
  puts ""
  puts "The following files have been added:"
  puts new_inventory - old_inventory
end

def print_delete_files(old_inventory, new_inventory)
  puts ""
  puts "The following files have been deleted:"
  puts old_inventory - new_inventory
end

if $0 == __FILE__
  check_usage
  compare_inventory_files ARGV[0], ARGV[1]
end